<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import WorldA from '@/components/ThreeJS/WorldCom/WorldCom.vue'

const data = reactive({
  objList: [
    { lon: 116.358976, lat: 39.803282, name: '中国', color: '#1FFBC6' },
    { lon: 139.812263, lat: 35.677294, name: '日本', color: '#A41FE8' },
    { lon: 77.198596, lat: 28.575136, name: '印度', color: '#E8BB1F' },
    { lon: -77.02238, lat: 38.900042, name: '美国', color: '#E81F56' },
    { lon: 31.266092, lat: 30.085626, name: '埃及', color: '#1FFBC6' },
    { lon: 103.813654, lat: 1.291125, name: '新加坡', color: '#E8BB1F' },
    { lon: -47.930912, lat: -15.781949, name: '巴西', color: '#A41FE8' },
    { lon: 149.130214, lat: -35.318235, name: '澳大利亚', color: '#E81F56' },
  ],
  objList_2: [
    { lon: 116.358976, lat: 39.803282, name: '中国column', color: '#1FFBC6' },
    { lon: 139.812263, lat: 35.677294, name: '日本column', color: '#A41FE8' },
    { lon: 77.198596, lat: 28.575136, name: '印度column', color: '#E8BB1F' },
    { lon: -77.02238, lat: 38.900042, name: '美国column', color: '#E81F56' },
    { lon: 31.266092, lat: 30.085626, name: '埃及column', color: '#1FFBC6' },
    { lon: 103.813654, lat: 1.291125, name: '新加坡column', color: '#E8BB1F' },
    { lon: -47.930912, lat: -15.781949, name: '巴西column', color: '#A41FE8' },
    {
      lon: 149.130214,
      lat: -35.318235,
      name: '澳大利亚column',
      color: '#E81F56',
    },
  ],
  rotation: '关闭旋转',
})

const threeMapId = ref(null)

onMounted(() => {
  infoMap()
  columnChange()
  flyLineChange()
})

// 重置
const reset = () => {
  infoMap()
}

// 地球添加标记点
const infoMap = () => {
  for (let i = 0; i < data.objList.length; i++) {
    threeMapId.value.infoMark(data.objList[i])
  }
}

// 移动相机
const cameraPos = (item) => {
  threeMapId.value.cameraPos(item)
}

// 开启或关闭地球自动旋转
const rotationY = ref(false)
const rotationChange = () => {
  rotationY.value = !rotationY.value
  threeMapId.value.rotation()
  threeMapId.value.frameDivClose()
  data.rotation = rotationY.value == true ? '开启旋转' : '关闭旋转'
}

// 添加光柱infoColumn
const columnChange = () => {
  for (let i = 0; i < data.objList.length; i++) {
    threeMapId.value.infoColumn(data.objList[i])
  }
}
// 添加飞线infoFlyLine
const flyLineChange = () => {
  console.log('添加飞线')
  threeMapId.value.createFlyLine(data.objList)
}

// 删除所有标记点
const delAllChange = () => {
  for (let i = 0; i < data.objList.length; i++) {
    threeMapId.value.delAll(data.objList[i])
  }
  for (let i = 0; i < data.objList.length; i++) {
    threeMapId.value.delAll(data.objList[i])
  }
}

// 删除指定标记点
const delMarkChange = () => {
  let item = {
    name: '美国',
  }
  threeMapId.value.delMark(item)
}
</script>

<template>
  <div>
    <div class="home">
      <div class="rightMain" v-if="false">
        <div class="title">跳转操作</div>
        <div class="cont">
          <ul>
            <li v-for="(item, index) in data.objList" @click="cameraPos(item)">
              {{ item.name }}
            </li>
          </ul>
        </div>
        <div class="title">其他操作</div>
        <div class="cont">
          <ul>
            <li @click="rotationChange">{{ data.rotation }}</li>
            <li @click="columnChange">添加光柱</li>
            <li @click="delAllChange">删除所有</li>
            <li @click="delMarkChange">删除美国标记点</li>
          </ul>
        </div>
        <div class="title">重置操作</div>
        <div class="cont">
          <ul>
            <li @click="reset">初始化数据</li>
          </ul>
        </div>
      </div>
      <WorldA ref="threeMapId" />
    </div>
  </div>
</template>

<style lang="scss" scoped>
.home {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background-image: url('@/assets/images/temp/back.png');
  background-size: 100% 130%;
  .rightMain {
    position: absolute;
    right: 0;
    width: 300px;
    height: 100%;
    z-index: 100;
    padding: 10px;
    box-sizing: border-box;
    color: white;
    background-color: rgba(255, 255, 255, 0.2);
    .title {
      width: 100%;
      font-size: 16px;
      font-weight: bold;
      margin-bottom: 10px;
    }
    .cont {
      height: 150px;
      ul {
        padding: 0;
        margin-bottom: 0;
        li {
          list-style: none;
          float: left;
          width: 33.33%;
          padding: 10px 0;
          text-align: center;
          cursor: pointer;
          font-size: 14px;
          &:hover {
            color: aquamarine;
          }
        }
      }
    }
  }
}
</style>
